//
//  DownloadViewController.m
//  VPPublicUntilitisForPod
//
//  Created by verne on 2017/3/20.
//  Copyright © 2017年 vernepung. All rights reserved.
//

#import "DownloadViewController.h"
#import "VPHTTPRequestOperationManager.h"
#import "DownTableViewCell.h"
#import "DownloadModel.h"
#import "UtilsMacro.h"
#import "ConstMacro.h"

@interface DownloadViewController ()<UITableViewDelegate, UITableViewDataSource>{
    NSMutableArray<DownloadModel *> *models;
}

@property (strong, nonatomic) UITableView *testTableview;
@end

@implementation DownloadViewController
- (void)setupViews {
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSArray *arr = @[@"http://ttapi.ourteacher.com.cn:10000/resource/video/ad350f468b624239b81ed5fc586949a4_convert.mp4",
                     @"http://win.qbplays.top/ylmf32win7bendi4.php?Expires=1492747602&OSSAccessKeyId=STS.JaMcoon5mmq8u8bP284mJM6CX&Signature=lH6HdWXSsmoOzAuM7zpqZUFpPMw%3D&security-token=CAIS9wF1q6Ft5B2yfSjIq6L4KNXbg%2BpM2rPTdx7TtDJtOOJmovPoujz2IHxNfnZtBuAftvUxmG1U6f8YlqVxSpZCXUHFWtR0%2F4QPc%2F4K%2FlqC6aKP9rUhpMCPOwr6UmzWvqL7Z%2BH%2BU6muGJOEYEzFkSle2KbzcS7YMXWuLZyOj%2BwMDL1VJH7aCwBLH9BLPABvhdYHPH%2FKT5aXPwXtn3DbATgD2GM%2BqxsmsP%2Fnk5fNt0CC0gWgkLNEnemrfMj4NfsLFYxkTtK40NZxcqf8yyNK43BIjvwq1fYbpGiX54nMXQUMv0rfafCw9cZ0aRRlfe0lH79UvBl%2FLHGgQAW5GoABOahF2GBarZK6WyDP5WD4rLX31JF5DBJW2gJRyanykdiT1ci30C%2BAo93LKCI9bc%2FrVtty4RxrCSj4sTrRrkPb49CqrVWCWfvyjcBw9XdnjusaGMlMUj0TMwz0pm6%2FZV21PDypwJJuvbs",
                     @"http://baobab.wdjcdn.com/1442142801331138639111.mp4",
                     @"http://xz.cr173.com/soft2/sqlite_professional_mac.zip",
                     @"https://res.wx.qq.com/open/zh_CN/htmledition/res/dev/download/sdk/WeChatSDK1.7.3.zip",
                     @"http://wlyxdoccdn.ourteacher.com.cn/test/2017/ActivityClient/ProjectResources/308/Attachment/Activities/Attachment/StudyTask/2017-04-11/o_1bdebtrl5c9j1mhf12469da1phm0_%E9%99%84%E4%BB%B6.pdf?Expires=1492747602&OSSAccessKeyId=STS.JaMcoon5mmq8u8bP284mJM6CX&Signature=lH6HdWXSsmoOzAuM7zpqZUFpPMw%3D&security-token=CAIS9wF1q6Ft5B2yfSjIq6L4KNXbg%2BpM2rPTdx7TtDJtOOJmovPoujz2IHxNfnZtBuAftvUxmG1U6f8YlqVxSpZCXUHFWtR0%2F4QPc%2F4K%2FlqC6aKP9rUhpMCPOwr6UmzWvqL7Z%2BH%2BU6muGJOEYEzFkSle2KbzcS7YMXWuLZyOj%2BwMDL1VJH7aCwBLH9BLPABvhdYHPH%2FKT5aXPwXtn3DbATgD2GM%2BqxsmsP%2Fnk5fNt0CC0gWgkLNEnemrfMj4NfsLFYxkTtK40NZxcqf8yyNK43BIjvwq1fYbpGiX54nMXQUMv0rfafCw9cZ0aRRlfe0lH79UvBl%2FLHGgQAW5GoABOahF2GBarZK6WyDP5WD4rLX31JF5DBJW2gJRyanykdiT1ci30C%2BAo93LKCI9bc%2FrVtty4RxrCSj4sTrRrkPb49CqrVWCWfvyjcBw9XdnjusaGMlMUj0TMwz0pm6%2FZV21PDypwJJuvbs0cE4SRi742OgFcDir6hijtKqBXFz8JeA%3D",
                     @"http://win.qbplays.top/ylmf32win7bendi4.php?Expires=1492747602&OSSAccessKeyId=STS.JaMcoon5mmq8u8bP284mJM6CX&Signature=lH6HdWXSsmoOzAuM7zpqZUFpPMw%3D&security-token=CAIS9wF1q6Ft5B2yfSjIq6L4KNXbg%2BpM2rPTdx7TtDJtOOJmovPoujz2IHxNfnZtBuAftvUxmG1U6f8YlqVxSpZCXUHFWtR0%2F4QPc%2F4K%2FlqC6aKP9rUhpMCPOwr6UmzWvqL7Z%2BH%2BU6muGJOEYEzFkSle2KbzcS7YMXWuLZyOj%2BwMDL1VJH7aCwBLH9BLPABvhdYHPH%2FKT5aXPwXtn3DbATgD2GM%2BqxsmsP%2Fnk5fNt0CC0gWgkLNEnemrfMj4NfsLFYxkTtK40NZxcqf8yyNK43BIjvwq1fYbpGiX54nMXQUMv0rfafCw9cZ0aRRlfe0lH79UvBl%2FLHGgQAW5GoABOahF2GBarZK6WyDP5WD4rLX31JF5DBJW2gJRyanykdiT1ci30C%2BAo93LKCI9bc%2FrVtty4RxrCSj4sTrRrkPb49CqrVWCWfvyjcBw9XdnjusaGMlMUj0TMwz0pm6%2FZV21PDypwJJuvbs",
                     @"http://baobab.wdjcdn.com/1442142801331138639111.mp4",
                     @"http://xz.cr173.com/soft2/sqlite_professional_mac.zip",
                     @"https://res.wx.qq.com/open/zh_CN/htmledition/res/dev/download/sdk/WeChatSDK1.7.3.zip",
                     @"http://wlyxdoccdn.ourteacher.com.cn/test/2017/ActivityClient/ProjectResources/308/Attachment/Activities/Attachment/StudyTask/2017-04-11/o_1bdebtrl5c9j1mhf12469da1phm0_%E9%99%84%E4%BB%B6.pdf?Expires=1492747602&OSSAccessKeyId=STS.JaMcoon5mmq8u8bP284mJM6CX&Signature=lH6HdWXSsmoOzAuM7zpqZUFpPMw%3D&security-token=CAIS9wF1q6Ft5B2yfSjIq6L4KNXbg%2BpM2rPTdx7TtDJtOOJmovPoujz2IHxNfnZtBuAftvUxmG1U6f8YlqVxSpZCXUHFWtR0%2F4QPc%2F4K%2FlqC6aKP9rUhpMCPOwr6UmzWvqL7Z%2BH%2BU6muGJOEYEzFkSle2KbzcS7YMXWuLZyOj%2BwMDL1VJH7aCwBLH9BLPABvhdYHPH%2FKT5aXPwXtn3DbATgD2GM%2BqxsmsP%2Fnk5fNt0CC0gWgkLNEnemrfMj4NfsLFYxkTtK40NZxcqf8yyNK43BIjvwq1fYbpGiX54nMXQUMv0rfafCw9cZ0aRRlfe0lH79UvBl%2FLHGgQAW5GoABOahF2GBarZK6WyDP5WD4rLX31JF5DBJW2gJRyanykdiT1ci30C%2BAo93LKCI9bc%2FrVtty4RxrCSj4sTrRrkPb49CqrVWCWfvyjcBw9XdnjusaGMlMUj0TMwz0pm6%2FZV21PDypwJJuvbs0cE4SRi742OgFcDir6hijtKqBXFz8JeA%3D",
                     @"http://win.qbplays.top/ylmf32win7bendi4.php?Expires=1492747602&OSSAccessKeyId=STS.JaMcoon5mmq8u8bP284mJM6CX&Signature=lH6HdWXSsmoOzAuM7zpqZUFpPMw%3D&security-token=CAIS9wF1q6Ft5B2yfSjIq6L4KNXbg%2BpM2rPTdx7TtDJtOOJmovPoujz2IHxNfnZtBuAftvUxmG1U6f8YlqVxSpZCXUHFWtR0%2F4QPc%2F4K%2FlqC6aKP9rUhpMCPOwr6UmzWvqL7Z%2BH%2BU6muGJOEYEzFkSle2KbzcS7YMXWuLZyOj%2BwMDL1VJH7aCwBLH9BLPABvhdYHPH%2FKT5aXPwXtn3DbATgD2GM%2BqxsmsP%2Fnk5fNt0CC0gWgkLNEnemrfMj4NfsLFYxkTtK40NZxcqf8yyNK43BIjvwq1fYbpGiX54nMXQUMv0rfafCw9cZ0aRRlfe0lH79UvBl%2FLHGgQAW5GoABOahF2GBarZK6WyDP5WD4rLX31JF5DBJW2gJRyanykdiT1ci30C%2BAo93LKCI9bc%2FrVtty4RxrCSj4sTrRrkPb49CqrVWCWfvyjcBw9XdnjusaGMlMUj0TMwz0pm6%2FZV21PDypwJJuvbs",
                     @"http://baobab.wdjcdn.com/1442142801331138639111.mp4",
                     @"http://xz.cr173.com/soft2/sqlite_professional_mac.zip",
                     @"https://res.wx.qq.com/open/zh_CN/htmledition/res/dev/download/sdk/WeChatSDK1.7.3.zip",
                     @"http://wlyxdoccdn.ourteacher.com.cn/test/2017/ActivityClient/ProjectResources/308/Attachment/Activities/Attachment/StudyTask/2017-04-11/o_1bdebtrl5c9j1mhf12469da1phm0_%E9%99%84%E4%BB%B6.pdf?Expires=1492747602&OSSAccessKeyId=STS.JaMcoon5mmq8u8bP284mJM6CX&Signature=lH6HdWXSsmoOzAuM7zpqZUFpPMw%3D&security-token=CAIS9wF1q6Ft5B2yfSjIq6L4KNXbg%2BpM2rPTdx7TtDJtOOJmovPoujz2IHxNfnZtBuAftvUxmG1U6f8YlqVxSpZCXUHFWtR0%2F4QPc%2F4K%2FlqC6aKP9rUhpMCPOwr6UmzWvqL7Z%2BH%2BU6muGJOEYEzFkSle2KbzcS7YMXWuLZyOj%2BwMDL1VJH7aCwBLH9BLPABvhdYHPH%2FKT5aXPwXtn3DbATgD2GM%2BqxsmsP%2Fnk5fNt0CC0gWgkLNEnemrfMj4NfsLFYxkTtK40NZxcqf8yyNK43BIjvwq1fYbpGiX54nMXQUMv0rfafCw9cZ0aRRlfe0lH79UvBl%2FLHGgQAW5GoABOahF2GBarZK6WyDP5WD4rLX31JF5DBJW2gJRyanykdiT1ci30C%2BAo93LKCI9bc%2FrVtty4RxrCSj4sTrRrkPb49CqrVWCWfvyjcBw9XdnjusaGMlMUj0TMwz0pm6%2FZV21PDypwJJuvbs0cE4SRi742OgFcDir6hijtKqBXFz8JeA%3D"];
    NSArray *titleArr = @[@"内网Mp4文件",
                          @"win7系统",
                          @"baobei3",
                          @"sqlite_professional的Zip文件",
                          @"WeChatSDK1.7.3.zip",
                          @"阿里云.pdf",
                          @"win7系统",
                          @"baobei3",
                          @"sqlite_professional的Zip文件",
                          @"WeChatSDK1.7.3.zip",
                          @"阿里云.pdf",
                          @"win7系统",
                          @"baobei3",
                          @"sqlite_professional的Zip文件",
                          @"WeChatSDK1.7.3.zip",
                          @"阿里云.pdf"];
    
    
    models = [NSMutableArray array];
    DownloadModel *model;
    for (NSInteger i = 0; i < arr.count; i++) {
        model = [[DownloadModel alloc]init];
        model.title = titleArr[i];
        model.fileUrl = arr[i];
        DownloadModel *foundModel = (DownloadModel*)[[VPHTTPRequestOperationManager manager] isExistsModel:model];
        if (foundModel) {
            model = foundModel;
            //url需要替换成新的，阿里云30分钟变一次token
            model.fileUrl = arr[i];
            DLog(@"______\n:%@",model.fileTempPath);
        }
        [models addObject:model];
    }
    [self.view addSubview:self.testTableview];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.statusBarState = VPStatusBarStateHide;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.statusBarState = VPStatusBarStateShow;
}

#pragma mark - UITableViewDataSource & UITableViewDelegate
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger row = indexPath.row;
    DownTableViewCell *cell = [DownTableViewCell loadFromXib];
    [cell fillCellWithObject: models[row]];
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return models.count;
}

#pragma mark - getter & setter
- (UITableView *)testTableview{
    if (!_testTableview){
        _testTableview = [[UITableView alloc]initWithFrame:kRect(0, 0, kMainBoundsWidth, kMainBoundsHeight - kNavBarHeightWithStatusBarHeight - kTabBarHeight)];
        _testTableview.backgroundColor = [UIColor whiteColor];
        _testTableview.dataSource = self;
        _testTableview.delegate = self;
        _testTableview.rowHeight = 80.f;
    }
    return _testTableview;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)prefersStatusBarHidden{
    return YES;
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
